import moment from 'moment';
import {mapState} from 'vuex'
import {
  deepCopyObj
} from '../../../assets/js/help.js'

function getFontCss(treeId, treeNode) {
  return (!!treeNode.highlight) ? {
    color: "#A60000",
    "font-weight": "bold"
  } : {
    color: '',
    "font-weight": ''
  };
};

export default {
  data() {
    return {
      onlineSaleStatus: '',
      isShowSwitch: true,
      isShowCouponStatus: true,
      switchCouponStatus: '', //线上购买优惠券开关
      bigImgPath: '',
      isLimitEdit: false,
      editTitle: '',
      couponTypeName: "",
      couponNameSelected: '', //优惠券的名字(被选择)
      sellerNameListSelected: [], //商家名称数组(被选择)
      couponNameList: [], //优惠券列表
      sellerNameList: [], //商家列表
      sellerIdList: [], //商家id列表
      checkAll: false, //商家购买设置-是否全选
      isIndeterminate: false, //购买设置-全选框样式
      selectedParkingLot: '', //已选择的停车场树数据
      selectedParkingLotStr: '', //已选择停车场
    }
  },
  created() {
    this.fetchTraderCouponOnlineSaleStatus()
  },
  mounted() {
    const self = this
    window.addEventListener('storage', function(ev) {
			if (ev.key == 'onlineSaleStatus_set') {
        if(ev.newValue===null || ev.newValue==='') return;
				let newVal = JSON.parse(ev.newValue)
				self.onlineSaleStatus = Number(newVal)
			}
		});
  },
  computed: {
    ...mapState(['skinType']),
    inputParkstr: function (val) {
      if (this.MerchantCouponsModalData.inputParks.length > 0) {
        return this.MerchantCouponsModalData.inputParks.join(',')
      } else {
        return '';
      }
    },
  },
  watch: {
    'MerchantCouponsModalData.couponType': function (newValue) {
      switch (Number(newValue)) {
        case 1:
          this.couponTypeName = '金额'
          break;
        case 2:
          this.couponTypeName = '折扣'
          break;
        case 3:
          this.couponTypeName = '面值'
          break;
        case 4:
          this.couponTypeName = '优惠时间'
          break;
        case 5:
          this.couponTypeName = '计费组编号'
          break;
        default:
          break;
      }
    },
    skinType (Val) {
      this.isShowSwitch = false
      this.$nextTick(() => {
        this.isShowSwitch = true
      })
    }
  },
  methods: {
    // 查看优惠券详情
    checkSellCoupon_detail(rowData){
      this.$refs.sellManageComponent.check_sellCoupon_detail(rowData)
    },
    // 券类型选项切换
    changeFaceValue(val){
      this.MerchantCouponsModalData.basicData.faceValue = 1
      if (this.$refs.MerchantCoupons_form) {
        this.$refs.MerchantCoupons_form.validateField('faceValue');
      }
      this.MerchantCouponsModalData.basicData.faceValue = ''
    },
    // 优惠券列表搜索框
    searchCouponKeyWord(){
      let keyword = this.MerchantCouponsModalData.shoppingSetup.couponName
      this.MerchantCouponsModalData.shoppingSetup.couponList.forEach(element=>{
        if(element.name.indexOf(keyword)>-1 || !keyword){
          element.isHidden = false
        }else{
          element.isHidden = true
        }
      })
      this.MerchantCouponsModalData.shoppingSetup.couponList.push({})
      this.$nextTick(()=>{
        this.MerchantCouponsModalData.shoppingSetup.couponList.pop()
      })
    },
    handleCheckAllChange2(val) {
      let allCoupon = []
      this.MerchantCouponsModalData.shoppingSetup.couponList.forEach(element=>{
        if(!element.isHidden){
          allCoupon.push(element.id)
        }
      })
      this.MerchantCouponsModalData.shoppingSetup.checkedCoupons = val ? allCoupon : [];
      this.isIndeterminate = false;
    },
    handleCheckedChange2(value) {
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.MerchantCouponsModalData.shoppingSetup.couponList.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.MerchantCouponsModalData.shoppingSetup.couponList.length;
    },
    // 删除停车场时调用的函数
    delectSelectParkItem(index, parkId) {
      var _this = this;
      _this.tableData.parkItems.splice(index, 1);
      if (_this.MerchantCouponsModalData.basicData.financialParkId == parkId) {
        _this.MerchantCouponsModalData.basicData.financialParkId = null;
      }
    },
    // tab步骤切换
    toggleTab(tabName){
      if(this.MerchantCouponsModalData.tabName==tabName){
        return;
      }
      this.MerchantCouponsModalData.tabName = tabName
    },
    switchCouponBtnStatus(){ //更新线上购买优惠券开关
      let self = this,
      params = {
        isTraderCouponPay: self.switchCouponStatus==true ? 1 : 0
      };
      API.fetchGet('coupon/updateTraderCouponOnlineSaleStatus.do',params).then(res=>{
        
      },err=>{})
    },
    // 获取当前帐号的线上购买的开关状态
    fetchTraderCouponOnlineSaleStatus() {
      let self = this;
      API.fetchGet("/trader/getTraderCouponOnlineSaleStatus.do", {}).then(
        res => {
          if (res.status == 1) {
            self.onlineSaleStatus = res.data;
          }
        },
        err => {}
      );
    },
    // getSwitchCouponBtnStatus(){ //获取线上购买优惠券开关
    //   let self = this
    //   API.fetchGet('coupon/getTraderCouponOnlineSaleStatus.do',{}).then(res=>{
    //     if(res.data==null){
    //       self.isShowCouponStatus = false
    //       return  
    //     }
    //     self.switchCouponStatus = res.data
    //     self.isShowCouponStatus = true
    //   },err=>{})
    // },
    getList() {
      this.getItemList();
    },
    openSelectParkModal() {
      var _self = this;
      _self.toOpenModal('selectParkModal');
      this.initParkTree("ParkTree");
    },
    initParkTree(treeId) {
      var _self = this;
      API.fetchGet('/coupon/getParkingBaseDataTree.do', {})
        .then(res => {
          var data = res;
          if (data != null) {
            var nodes = data.data;
            var jsonStr = JSON.stringify(nodes);
            jsonStr = jsonStr.replace(/(\"isArea\"\:true\,)/g, '"isArea": true,"chkDisabled":true, "nocheck":true,');
            nodes = JSON.parse(jsonStr);
            var settings = {
              check: {
                enable: true,
                chkStyle: "checkbox",
                radioType: "all"
              },
              view: {
                showIcon: false,
                showLine: false,
              },
              callback: {
                onClick: function (event, treeId, treeNode) {
                  var treeObj = $.fn.zTree.getZTreeObj('ParkTree');
                  treeObj.checkNode(treeNode, true, false);
                  if (treeNode.isArea) {
                    return;
                  }
                },
              }
            };
            $.fn.zTree.destroy("ParkTree");

            var treeObj = $.fn.zTree.init($("#ParkTree"), settings, nodes);
            treeObj.expandAll(true);
            if(_self.MerchantCouponsModalData.basicData.parkList && _self.MerchantCouponsModalData.basicData.parkList.length){
              let parkIdList = _self.MerchantCouponsModalData.basicData.parkList.join(',')
              let treeNode = treeObj.getCheckedNodes(false)
              for(let i = 0; i<treeNode.length; i++){
                if(parkIdList.indexOf(treeNode[i].value)>-1){
                  treeObj.checkNode(treeNode[i], true, false);
                } 
              }
            }
          } else {
            _self.showToast('暂时没有停车场可选', 2, 3000);
          }
        }, err => {})

    },
    selectParkSure() {
      var self = this,
        nodes = [];
      var treeObj = $.fn.zTree.getZTreeObj("ParkTree");
      nodes = treeObj.getCheckedNodes(true); // 获取tree被勾选的节点
      var parkList = new Array();
      // 初始化表格显示数据以及提交的表格参数
      self.tableData = {
        ParkNameList: [],
        parkIdList: [],
        parkVipTypeId: [],
        parkItems: [],
      };
      for (var i = 0; i < nodes.length; i++) {
        if (!nodes[i].isArea) {
          parkList.push(nodes[i]);
        }
      }
      if (parkList.length <= 0) {
        this.showToast('请选择一个停车场', 0, 2000)
        return;
      }
      self.selectedParkingLotStr = ''
      self.selectedParkingLot = []
      self.MerchantCouponsModalData.basicData.financialParkId = ''
      self.MerchantCouponsModalData.basicData.parkList = []; //停车场数字id
      self.MerchantCouponsModalData.basicData.inputParks = []; //停车场名
      if(parkList.length==1){
        self.MerchantCouponsModalData.basicData.financialParkId = parkList[0].value
      }
      for (var i = 0; i < parkList.length; i++) {
        let obj = {}
        obj.name = parkList[i].name
        obj.value = parkList[i].value
        self.selectedParkingLot.push(parkList[i].name)
        self.tableData.parkItems.push(obj)
        self.MerchantCouponsModalData.basicData.parkList.push(parkList[i].value);
        self.MerchantCouponsModalData.basicData.inputParks.push(parkList[i].name);
      }
      this.$refs.MerchantCoupons_form.validateField('parkJson')

      if(self.MerchantCouponsModalData.type=='add'){ //新增优惠券
        self.fetchBusinessList(); //获取停车场对应商家列表数据
      }
      this.$nextTick(()=>{
        self.selectedParkingLotStr = self.selectedParkingLot.join('/')
      })
      self.closed('selectParkModal');
    },
    //获取停车场对应商家列表数据
    fetchBusinessList(){
      let self = this
      let params = {
        parkIds: self.MerchantCouponsModalData.basicData.parkList.join(','),
        sort: true
      }
      API.fetchGet('/coupon/getTrader2Sell.do',params).then(res=>{
        if(res.data && res.data.length){
          self.MerchantCouponsModalData.shoppingSetup.couponList = res.data
          self.MerchantCouponsModalData.shoppingSetup.couponList.forEach(element=>{
            element.isHidden = false
          })
        }
      },err=>{})
    },
    function_comfirm(type, id) {
      if (this.selectionList.length > 0 || id) {
        var idList = [];
        var params = {};
        if (id) {
          params.id = id
        } else {
          this.selectionList.forEach(function (element) {
            idList.push(element.id)
          }, this);
          params.id = idList.join(',');
        }
        switch (type) {
          case 'DT': //删除优惠
            params.url = '/coupon/del.do';
            this.function_comfirm_callback(params)
            break;
          case 'QY': //启用
            params.url = '/coupon/enable.do';
            this.function_comfirm_callback(params)
            break;
          case 'DJ': //冻结
            params.url = '/coupon/frozen.do';
            this.function_comfirm_callback(params)
            break;
          default:
            break;
        }
      }
    },
    function_comfirm_callback(params) {
      API.fetchGet(params.url, params)
        .then(res => {
          this.showToast(res.message, 1, 2000)
          this.getItemList();
        }, err => {
          
        })
    },
    ParkListModal_open(row) {
      let self = this;
      let params = {
        'couponTmpId': row.id
      }
      API.fetchGet('/coupon/couponParkList.do', params)
        .then(res => {
          self.ParkListModalData.list = []
          self.tableData.parkItems = []
          for(let i = 0; i<res.data.length; i++){
            let objTemp = res.data[i]
            let obj = {}
            let tempObj = {}
            tempObj.name = objTemp.name
            tempObj.address = objTemp.address
            tempObj.value = objTemp.id
            self.tableData.parkItems.push(tempObj)
            obj.name = objTemp.name
            obj.address = objTemp.address
            obj.area = objTemp.area
            obj.isTradecouponOnlinesettle = objTemp.isTradecouponOnlinesettle
            obj.description = objTemp.description
            self.ParkListModalData.list.push(obj)
          }
          this.toOpenModal('ParkListModal');
        }, err => {})
    },
    // 购买配置-打开修改框
    shoppingSetup_open(rowData){
      let self = this
      self.editTitle = "购买配置"
      self.MerchantCouponsModalData.type = 'edit'
      self.MerchantCouponsModalData.tabName = 'higherTab'
      self.MerchantCouponsModalData.basicData.id = rowData.id
      self.MerchantCouponsModalData.basicData.name = rowData.name
      self.MerchantCouponsModalData.shoppingSetup = { 
        couponName: '', //优惠券名称
        checkedCoupons: [],
        couponList: [],
        couponIdListStr:'',
      }
      self.fetchShoppingSetupData(rowData.id);
      self.toOpenModal('MerchantCouponsModal')
    },
    // 购买配置-修改-保存
    shoppingSetupEdit_save(){
      let _this = this
      let params = {
        couponId: _this.MerchantCouponsModalData.basicData.id
      }
      if(_this.MerchantCouponsModalData.shoppingSetup.checkedCoupons && _this.MerchantCouponsModalData.shoppingSetup.checkedCoupons.length){
        params.traderIdListStr = _this.MerchantCouponsModalData.shoppingSetup.checkedCoupons.join(',')
      }
      API.fetchGet('/coupon/modifyCouponBuySet.do',params).then(res=>{
        if(res.status==1){
          _this.showToast('保存成功',1,1500)
          _this.closed('MerchantCouponsModal')
        }
      },err=>{})
    },
    async MerchantCouponsEditModal_open(itemData,type) {
      let self = this;
      itemData.sellNum = itemData.totalNum - itemData.totalAvilableToBuy; //总数-已售=可售
      if (type==1 && itemData.sellNum > 0) { //修改基础信息
        self.showToast('操作提示 : 已经销售的券，不可修改', 0, 2000);
        return;
      } 
      let initData = itemData;
      let parkList = [];
      let inputParks = [];
      self.tableData.parkItems = []
      self.checkAll = false
      self.isIndeterminate = false 
      // 计费组
      await API.fetchGet('/coupon/couponParkList.do', {
        'couponTmpId': initData.id
      }).then(res => {
        if (res.status == 1) { 
          let data = res.data;
          for (let i = 0; i < data.length; i++) {
            let tempObj = {}
            tempObj.name = data[i].name
            tempObj.address = data[i].address
            tempObj.value = data[i].id
            self.tableData.parkItems.push(tempObj)
            parkList.push(data[i].id);
            inputParks.push(data[i].name);
          }
        }
      }, err => {});
      var couponRule = function () {
        switch (initData.couponRule) {
          case 0:
            return '0'
          case 1:
            return '1'
          case 2:
            return '2'
          case 3:
            return '3'
          default:
            return null;
        }
      }();
      var balanceType = function () {
        switch (initData.balanceType) {
          case "销售结算":
            return '0'
          case "发放结算":
            return '1'
          case "使用结算":
            return '2'
          default:
            return null;
        }
      }();
      var couponType = function () {
        switch (initData.couponType) {
          case "免费券":
            return '0'
          case "金额扣减券":
            return '1'
          case "金额折扣券":
            return '2'
          case "金额固定值券":
            return '3'
          case "时间券":
            return '4'
          case "不同计价券":
            return '5'
          default:
            return null;
        }
      }();
      self.MerchantCouponsModalData = {
        tabName: type==1 ? 'basicTab' : 'higherTab',
        type: "edit",
        hasDiscount: initData.realPrice ? 1 : 0,
        moreSetupShow: false, //更多设置是否显示
        basicData: {
          tmpId: initData.couponTmpId,
          id: itemData.id,
          name: itemData.name,
          parkList: parkList,
          inputParks: inputParks,
          balanceType: balanceType,
          sellFromTo: [new Date(initData.sellFrom), new Date(initData.sellTo)],
          validFromTo: [new Date(initData.validFrom), new Date(initData.validTo)],
          validDay: initData.validDay,
          couponType: couponType,
          faceValue: initData.faceValue,
          originalPrice: initData.originalPrice,
          realPrice: initData.realPrice,
          useRuleMin: initData.useRule ? initData.useRule.split('~')[0] : 0,
          useRuleMax: initData.useRule ? initData.useRule.split('~')[1] : 9999,
          totalNum: initData.totalNum ? initData.totalNum : null,
          remark: initData.remark,
          isLimitTotal: initData.totalNum ? 0 : 1,
          couponRule: couponRule ? couponRule : null,
          useParkingFee: initData.useParkingFee,
          maxCoverNum:initData.maxCoverNum,
          expireRefund: initData.expireRefund,
          financialParkId: initData.financialParkId,
          isCover: initData.isCover,
          parkJson:[],
        },
        shoppingSetup:{ //购买配置obj
          couponName: '', //优惠券名称
          checkedCoupons: [],
          couponList: [],
          couponIdListStr:'',
        },
      };
      if(couponType==2){
        self.MerchantCouponsModalData.basicData.faceValue = initData.faceValue*10
      }
      self.selectedParkingLot = inputParks
      self.selectedParkingLotStr = inputParks.join('/')
      if(type==1){ //基础信息
        self.editTitle = "基础信息"
      }
      self.toOpenModal('MerchantCouponsModal');
    },
    // 获取购买配置数据
    async fetchShoppingSetupData(id){
      let self = this
      let params = {
        couponId: id,
        sort: true
      }
      await API.fetchGet('/coupon/getTrader2Sell.do',params).then(res=>{
        self.MerchantCouponsModalData.shoppingSetup.couponList = res.data
        self.MerchantCouponsModalData.shoppingSetup.couponList.forEach(element=>{
          element.isHidden = false
          if(element.checked){
            self.MerchantCouponsModalData.shoppingSetup.checkedCoupons.push(element.id)
          }
        })
      },err=>{})
    },
    MerchantCouponsModal_open() {
      var _this = this;
      var tenYear = [
        new Date(moment().format('YYYY-MM-DD 00:00:00')),
        new Date(moment().add(10, 'year').subtract(1, 'days').format('YYYY-MM-DD 23:59:59'))
      ];
      _this.checkAll = false
      _this.isIndeterminate = false 
      _this.tableData.parkItems = []
      _this.selectedParkingLot = []
      _this.selectedParkingLotStr = ''
      _this.MerchantCouponsModalData = {
        type: "add",
        tabName: 'basicTab', //tab切换
        hasDiscount: 0, //是否有折扣价
        moreSetupShow: false, //更多设置是否显示
        basicData:{ //基础信息obj
          id: null,
          name: "",
          parkList: [],
          inputParks: [],
          balanceType: 0,
          sellFromTo: tenYear,
          validFromTo: tenYear,
          validDay: 1440,
          couponType: "0",
          faceValue: "",
          originalPrice: "",
          realPrice: "",
          useRuleMin: 0,
          useRuleMax: 9999,
          totalNum: "",
          remark: '',
          isLimitTotal: 1,
          couponRule: '0',
          useParkingFee: 0,
          maxCoverNum: 1,
          expireRefund:0,
          financialParkId: '',
          isCover: 0, //是否可叠加
          parkJson: []
        },
        shoppingSetup:{ //购买配置obj
          couponName: '', //优惠券名称
          checkedCoupons: [],
          couponList: [],
          couponIdListStr:'',
        },
      };
      _this.editTitle = '新增优惠券';
      _this.toOpenModal('MerchantCouponsModal');
    },
    MerchantCouponsModal_save(event, formName) {
      var _this = this;
      _this.$refs['MerchantCoupons_form'].validate(async (valid) => {
        if (valid) {
          var params = deepCopyObj(_this.MerchantCouponsModalData.basicData);
          if (params.financialParkId=='') {
            _this.showToast("请选择财务主体", 0, 2000)
            return;
          }
          if (Number(params.useRuleMax) <= Number(params.useRuleMin)) {
            _this.showToast("使用添加后项不能大于前项", 0, 2000)
            return;
          }
          params.useRule = params.useRuleMin + "~" + params.useRuleMax;

          if(!_this.MerchantCouponsModalData.hasDiscount){ //无折扣价
            params.realPrice = params.originalPrice
          }

          if (Number(params.originalPrice) < Number(params.realPrice)) {
            _this.showToast("折扣价不能大于原价", 0, 2000)
            return;
          }
          if (!(params.sellFromTo && params.validFromTo)) {
            _this.showToast("请选择时间条件", 0, 2000)
            return;
          }
          if (Number(params.couponType) === 0) {
            params.faceValue = 0;
          }
          if(Number(params.couponType) == 2){ //金额折扣券
            params.faceValue = Number(params.faceValue)*0.1
            params.faceValue = params.faceValue.toFixed(1)
          }
          params.sellFrom = moment(_this.MerchantCouponsModalData.basicData.sellFromTo[0]).format('YYYY-MM-DD HH:mm:ss');
          params.sellTo = moment(_this.MerchantCouponsModalData.basicData.sellFromTo[1]).format('YYYY-MM-DD 23:59:59');
          params.validFrom = moment(_this.MerchantCouponsModalData.basicData.validFromTo[0]).format('YYYY-MM-DD HH:mm:ss');
          params.validTo = moment(_this.MerchantCouponsModalData.basicData.validFromTo[1]).format('YYYY-MM-DD 23:59:59');
          if (Number(params.isLimitTotal) == 1) {
            params['totalNum'] = 0;
          }

          if (Number(params.couponRule) >= 2) {
            params['useParkingFee'] = 0;
          }
          
          if(_this.MerchantCouponsModalData.shoppingSetup.checkedCoupons && _this.MerchantCouponsModalData.shoppingSetup.checkedCoupons.length){
            params.traderIdListStr = _this.MerchantCouponsModalData.shoppingSetup.checkedCoupons.join(',')
          }

          if (_this.MerchantCouponsModalData.type == 'add') {
            var url = '/coupon/add.do'
          } else {
            var url = '/coupon/modify.do'
          }
          var flag = false
          await API.fetchPost(url, params).then(response => {
            if (response.status == 1) {
              flag = true
              params.id = response.data
              _this.tableData.parkItems = []
              _this.closed('MerchantCouponsModal');
            } else {
              _this.showToast(res.message, 2, 2000)
              return;
            }
          }, err => {})
        } else {
          return false;
        }
        if(flag){ //操作成功
          _this.getList();
          if(_this.MerchantCouponsModalData.type == 'add'){ //新增
            // 询问是否马上售卖
            _this.isSellAtOnce(params)
          }else if(_this.MerchantCouponsModalData.type == 'edit'){
            _this.showToast('修改成功', 1, 2000);
          }
        }
      });
    },
    // 售卖操作
    async toSell(rowData){
      if(rowData.status=='未启用'){
        this.showToast('该优惠券未启用,请先启用该优惠券',0,2000);
        return
      }
      let parkIds = ''
      await API.fetchGet('/coupon/couponParkList.do',{couponTmpId:rowData.couponTmpId}).then(res=>{
        if(Array.isArray(res.data) && res.data.length){
          let tmpArr = []
          res.data.forEach(elem=>{
            tmpArr.push(elem.id)
          })
          parkIds = tmpArr.join(',')
        }
      },err=>{})
      this.$refs.sellManageComponent.SellCouponsModal_open(rowData,parkIds)
    },
    // 询问是否马上售卖
    isSellAtOnce(curCouponObj){
      let self = this
      this.showDialog("马上售卖此优惠券？",['售 卖','取 消'], function(){
        self.$refs.sellManageComponent.SellCouponsModal_open(curCouponObj)
      },"售卖-"+curCouponObj.name)
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    //获取列表
    getItemList() {
      let self = this,
        params = {
          page: this.pageNumber,
          rp: this.pageSize
        };
      params = $.extend({}, params, self.otherParams, self.searchParams);
      API.fetchGet('/coupon/getListByPage.do', params)
        .then(res => {
          let data = res.data,
            list = data.rows;
          self.tbodysInfo = list;
          self.total = data.total;
        }, err => {})
    },
    toBatchOprators(name, data) {
      switch (name) {
        case 'bt_correct':
          this.toAdjust(data);
          break;
        default:
          break;
      }
    },
    toAdjust() {},
    exportData() {
      let self = this;
      let params = {};
      params = $.extend({}, params, this.searchParams);
      this.toExport('monthTicketBill/detail/export.do', params);
    },
    // 商家购买设置
    SellerPurchaseSetupModal_open() {
      let _this = this;
      _this.couponNameSelected = '';
      _this.sellerNameListSelected = [];
      _this.checkAll = false
      _this.isIndeterminate = false
      //获取优惠券列表信息
      API.fetchGet('/coupon/getAuthCouponList.do',{})
      .then(res => {
        _this.couponNameList = res.data;
      },err => {});
      //获取商家列表信息
      API.fetchGet('/coupon/getAuthTraderList.do',{})
      .then(res => {
        _this.sellerIdList = []
        _this.sellerNameList = res.data
        _this.sellerNameList.map(function(value){
          _this.sellerIdList.push(value.id)
        })
      },err => {})
      _this.toOpenModal('SellerPurchaseSetupModal');
    },
    //商家购买设置--checkbox全选
    handleCheckAllChange(val) {
      this.sellerNameListSelected = val ? this.sellerIdList : [];
      this.isIndeterminate = false;
    },
    //多选框
    handleCheckedSellerNameListChange(value){
      let checkedCount = value.length;
      this.checkAll = checkedCount === this.sellerNameList.length;
      this.isIndeterminate = checkedCount > 0 && checkedCount < this.sellerNameList.length;
    },
    //优惠券单选事件
    getSelectedSellerForCoupon(){
      let _this = this;
      let params = {
        couponId: _this.couponNameSelected
      };
      API.fetchGet('/coupon/getBuyset.do',params).then(res => {
        _this.sellerNameListSelected = res.data.traderIdList
        _this.checkAll = false
      })
    },
    //提交商家购买设置数据
    submitSellerPurchaseSetup(){
      let _this = this
      let params = {
        couponId: this.couponNameSelected,
        traderIdList: this.sellerNameListSelected
      };
      if(this.couponNameSelected==''){
        _this.showToast("请先选择优惠券", 0, 2000);
        return
      }
      API.fetchPost('/coupon/buyset.do',params).then(res => {
        if (res.status == 1) {
          _this.showToast('操作成功', 1, 2000);
          _this.closed('SellerPurchaseSetupModal');
        } else {
          _this.showToast(res.message, 2, 2000)
          return;
        }
      })
    },
    // 删除停车场时调用的函数
    delectSelectParkItem(index, parkId) {
      var _this = this;
      _this.tableData.parkItems.splice(index, 1);
      if (_this.MerchantCouponsModalData.basicData.financialParkId == parkId) {
        _this.MerchantCouponsModalData.basicData.financialParkId = null;
      }
    },
  },
  filters: {
    totalNumShow: function (value) {
      if (value == 0) {
        return "无限";
      }
      return value;
    }
  }

}
